package com.miracle9.game.dao;

import com.miracle9.game.entity.MermaidDesk;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MermaidDeskServiceDao extends SqlOperating<MermaidDesk, Integer> {

    public List<Integer> getDeskIdsByRoomId(int roomId){
        return (List<Integer>)getSession().createQuery("select id from MermaidDesk where roomId = ?").setParameter(0, roomId).list();
    }

    public List<MermaidDesk> getMermaidDesks() {
        return q_CreateSqlList("from MermaidDesk order by roomId desc,orderBy", new Object[0]);
    }

    public void updateOrderByById(int id, int index) {
        q_CreateSql("update MermaidDesk set orderBy=? where id=?", new Object[]{Integer.valueOf(index), Integer.valueOf(id)}).executeUpdate();
    }

    public int getQuantityByRootId(int roomId) {
        return q_CreateSqlInt("select count(*) from MermaidDesk where roomId = ?", new Object[]{Integer.valueOf(roomId)});
    }

    public Integer saveReturnInteger(MermaidDesk desk) {
        return (Integer) saveReturn(desk);
    }

    public MermaidDesk getMermaidDesk(int id) {
        return (MermaidDesk) getById(Integer.valueOf(id));
    }

    public void updateSumInfoById(int id) {
        q_CreateSql("update MermaidDesk set sumYaFen=0,sumDeFen=0,sumSeat1YaFen=0,sumSeat2YaFen=0,sumSeat3YaFen=0,sumSeat4YaFen=0,sumSeat1DeFen=0,sumSeat2DeFen=0,sumSeat3DeFen=0,sumSeat4DeFen=0 where id=?", new Object[]{Integer.valueOf(id)}).executeUpdate();
    }

    public void updateMermaidDeskInfo(MermaidDesk desk) {
        MermaidDesk update = (MermaidDesk) getById(Integer.valueOf(desk.getId()));
        update.setName(desk.getName());
        update.setMinGold(desk.getMinGold());
        update.setExchange(desk.getExchange());
        update.setOnceExchangeValue(desk.getOnceExchangeValue());
        update.setGameDiff(desk.getGameDiff());
        update.setSiteType(desk.getSiteType());
        update.setAutoKick(desk.getAutoKick());
        update.setMinGunValue(desk.getMinGunValue());
        update.setMaxGunValue(desk.getMaxGunValue());
        update.setAddstepGunValue(desk.getAddstepGunValue());
        update.setState(desk.getState());
        update(update);
    }

    public void deleteById(int id) {
        deleteById(Integer.valueOf(id));
    }

    public void updateStateById(int id, int state) {
        q_CreateSql("update MermaidDesk set state=? where id=?", new Object[]{Integer.valueOf(state), Integer.valueOf(id)}).executeUpdate();
    }

}
